# -*- sh -*-
security_def_list="usm"
security_src_list=""
security_obj_list=""
security_lobj_list=""
security_ftobj_list=""
security_mod_list=" "

new_with_security=
new_with_out_security=`echo $with_out_security_modules | tr , ' '`

# Assign additional security modules
for i in `echo $with_security_modules | tr , ' '`; do
  if echo " $new_with_out_security " | $GREP " $i " > /dev/null; then
    echo
    AC_MSG_ERROR([security module conflict - $i both included and excluded])
  elif echo " $new_with_security " | $GREP " $i " > /dev/null ; then
    : # Double define, ignore
  else
    new_with_security="$new_with_security $i"
  fi
done

# Add default security modules
for i in $security_def_list; do
  if echo " $new_with_out_security " | $GREP " $i " > /dev/null; then
    : # Excluded, ignore
  elif echo " $new_with_security " | $GREP " $i " > /dev/null ; then
    : # Double define, ignore
  else
    new_with_security="$new_with_security $i"
  fi
done

# Generate output files
: ${security_init_file:='snmplib/snmpsm_init.h'}
: ${security_shutdown_file:='snmplib/snmpsm_shutdown.h'}
: ${security_incl_file:='include/net-snmp/library/snmpv3-security-includes.h'}

echo "/* This file is automatically generated by configure.  Do not modify by hand. */" > $security_init_file
echo "/* This file is automatically generated by configure.  Do not modify by hand. */" > $security_shutdown_file
echo "/* This file is automatically generated by configure.  Do not modify by hand. */" > $security_incl_file

for i in $new_with_security; do
  cfile="snmp"$i".c"
  hfile="snmp"$i".h"

  # make sure support exists for it
  if test -f $srcdir"/snmplib/"$cfile -a -f $srcdir"/include/net-snmp/library/"$hfile; then
    :
  else
    echo
    AC_MSG_ERROR(No such security module: $i / $cfile / $hfile)
  fi

  # define a bunch of stuff to enable it
  security_mod_list="${security_mod_list} $i"
  security_src_list="$security_src_list $cfile"
  security_src_list="$security_src_list $cfile"
  security_hdr_list="$security_hdr_list $hfile"
  security_obj_list="$security_obj_list snmp"$i".o"
  security_lobj_list="$security_lobj_list snmp"$i".lo"
  security_ftobj_list="$security_ftobj_list snmp"$i".ft"
  echo "init_"$i"();" >> $security_init_file
  echo "shutdown_"$i"();" >> $security_shutdown_file
  echo "#include <net-snmp/library/$hfile>" >> $security_incl_file
  def_name="AS_TR_CPP([NETSNMP_SECMOD_$i])"
  AC_DEFINE_UNQUOTED($def_name)
done

